package com.design01_builder.pattern02_factory.schemes01.control;

import com.alibaba.fastjson.JSON;
import com.design01_builder.pattern02_factory.schemes01.entry.AwardInfo;
import com.design01_builder.pattern02_factory.schemes01.entry.DiscountResult;
import com.design01_builder.pattern02_factory.schemes01.entry.SmallGiftInfo;
import com.design01_builder.pattern02_factory.schemes01.service.DiscountService;
import com.design01_builder.pattern02_factory.schemes01.service.SmallGiftService;
import com.design01_builder.pattern02_factory.schemes01.service.YouKuMemberService;
import com.design01_builder.pattern02_factory.simple_factory.entry.ResponseResult;

import java.util.UUID;

/**
 * @ClassName DeliverController
 * @Description TODO
 * @Author zhangjunhao
 * @DATE 2023/9/1 0:43
 */
public class DeliverController {

    /**
     * 按照类型的不同发放商品
     * 奖品类型: 1 打折券 ,2 优酷会员,3 小礼品
     * @return
     */
    public ResponseResult awardToUser(AwardInfo awardInfo) {
        if (awardInfo.getAwardTypes() == 1) {
            //打折券
            DiscountService discountService = new DiscountService();
            DiscountResult result =
                    discountService.sendDiscount(awardInfo.getUid(), awardInfo.getAwardNumber());
            System.out.println("打折券发放成功!" + JSON.toJSON(result));
        } else if (awardInfo.getAwardTypes() == 2) {
            //优酷会员

            //获取用户手机号
            String bindMobile = awardInfo.getExtMap().get("phone");
            //调用service
            YouKuMemberService youKuMemberService = new
                    YouKuMemberService();
            youKuMemberService.openMember(bindMobile, awardInfo.getAwardNumber());
            System.out.println("优酷会员发放成功!");
        } else if (awardInfo.getAwardTypes() == 3) {

            /*
              小礼品
               封装收货用户信息
            */
            SmallGiftInfo smallGiftInfo = new SmallGiftInfo();
            smallGiftInfo.setUserName(awardInfo.getExtMap().get("username"));
            smallGiftInfo.setOrderId(UUID.randomUUID().toString());
            smallGiftInfo.setRelAddress(awardInfo.getExtMap().get("adderss"));
            SmallGiftService smallGiftService = new SmallGiftService();
            Boolean isSuccess = smallGiftService.giveSmallGift(smallGiftInfo);
            System.out.println("小礼品发放成功!" + isSuccess);
        }
        return null;
    }
}
